//
//  WCAddrListCell.m
//  CBT
//
//  Created by apple on 2019/7/8.
//  Copyright © 2019 Mr.Zhang. All rights reserved.
//

#import "WCAddrListCell.h"

@implementation WCAddrListCell

+ (instancetype)createTableView:(UITableView *)tableView {
    WCAddrListCell *cell = [tableView dequeueReusableCellWithIdentifier:@"addrlistCell"];
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
    cell.backgroundColor = [UIColor colorWithRed:237/255.0 green:237/255.0 blue:237/255.0 alpha:1];
    
    [cell makeViews];
    
    return cell;
}

- (void)makeViews {
    
    CGFloat width = (SCREEN_WIDTH-30);
    
    [self.contentView addSubview:self.bgview];
    [self.bgview mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(15);
        make.top.mas_equalTo(18);
        make.height.mas_equalTo(94);
        make.width.mas_equalTo(width);
    }];
    
    [self.bgview addSubview:self.userNameLabel];
    [self.userNameLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(20);
        make.top.mas_equalTo(15);
        make.height.mas_equalTo(15);
        make.width.mas_equalTo(width-150);
    }];
    
    [self.bgview addSubview:self.phoneNumberLabel];
    [self.phoneNumberLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.mas_equalTo(-20);
        make.top.mas_equalTo(15);
        make.height.mas_equalTo(15);
    }];
    
    [self.bgview addSubview:self.addrDetailLabel];
    [self.addrDetailLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(20);
        make.right.mas_equalTo(-15);
        make.top.mas_equalTo(45);
        make.height.mas_equalTo(15);
    }];
    
    [self.bgview addSubview:self.editImageView];
    [self.editImageView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.mas_equalTo(-20);
        make.bottom.mas_equalTo(-10);
        make.width.mas_equalTo(21);
        make.height.mas_equalTo(19);
    }];
    
    [self.bgview addSubview:self.editBtn];
    [self.editBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.mas_equalTo(0);
        make.bottom.mas_equalTo(-5);
        make.width.mas_equalTo(60);
        make.height.mas_equalTo(40);
    }];
}

- (UIView *)bgview {
    if (!_bgview) {
        UIView *bgview = [[UIView alloc] init];
        bgview.layer.cornerRadius = 5;
        bgview.backgroundColor = [UIColor whiteColor];
        _bgview = bgview;
    }
    
    return _bgview;
}

- (UILabel *)userNameLabel {
    if (!_userNameLabel) {
        _userNameLabel = [[UILabel alloc] init];
        _userNameLabel.textColor = UIColorFromRGB(0x404040);
        _userNameLabel.font = [UIFont systemFontOfSize:13];
        _userNameLabel.text = @"--";
    }
    
    return _userNameLabel;
}

- (UILabel *)phoneNumberLabel {
    if (!_phoneNumberLabel) {
        _phoneNumberLabel = [[UILabel alloc] init];
        _phoneNumberLabel.textColor = UIColorFromRGB(0x404040);
        _phoneNumberLabel.font = [UIFont systemFontOfSize:13];
        _phoneNumberLabel.textAlignment = NSTextAlignmentRight;
        _phoneNumberLabel.text = @"--";
    }
    
    return _phoneNumberLabel;
}

- (UILabel *)addrDetailLabel {
    if (!_addrDetailLabel) {
        _addrDetailLabel = [[UILabel alloc] init];
        _addrDetailLabel.textColor = UIColorFromRGB(0x404040);
        _addrDetailLabel.font = [UIFont systemFontOfSize:13];
        _addrDetailLabel.text = @"--";
    }
    
    return _addrDetailLabel;
}


- (UIImageView *)editImageView {
    if (!_editImageView) {
        _editImageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"edit"]];
        _editImageView.hidden = YES;
    }
    
    return _editImageView;
}

- (UIButton *)editBtn {
    if (!_editBtn) {
        _editBtn = [UIButton buttonWithType:UIButtonTypeCustom];
        [_editBtn setImage:[UIImage imageNamed:@"edit"] forState:UIControlStateNormal];
//        _editBtn.backgroundColor = [UIColor redColor];
        [_editBtn addTarget:self action:@selector(btnclick) forControlEvents:UIControlEventTouchUpInside];
    }
    
    return _editBtn;
}

- (void)btnclick {
    if (self.editblock) {
        self.editblock();
    }
}


@end
